package com.iexbuy.ihg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;

import com.iexbuy.ihg.App;
import com.iexbuy.ihg.R;
import com.iexbuy.ihg.common.CommUtil;
import com.iexbuy.ihg.entity.YunItemListObject;
import com.iexbuy.ihg.ui.fragment.YunGuoItemDetailFragment;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

;

public class YunGuoItemListAdapter extends BaseAdapter {

	private List<YunItemListObject> datas = new ArrayList<YunItemListObject>();
	private Context context;

	public YunGuoItemListAdapter(Context context, List<YunItemListObject> datas) {
		super();
		this.context = context;
		if (datas != null) this.datas = datas;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int location) {
		return datas.get(location);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.fragment_yunguo_list_item, null);
		}
		YunItemListObject vo = (YunItemListObject)datas.get(position);
		convertView.setTag(vo);

		((TextView) convertView.findViewById(R.id.yungouName)).setText("[第"+vo.getPeriod()+"期] " + vo.getItemName());
		((TextView) convertView.findViewById(R.id.attendanceNo)).setText(vo.getAttandanceNumber());
		((TextView) convertView.findViewById(R.id.totalRequireNo)).setText(vo.getRequiredTotalNumber());
		((TextView) convertView.findViewById(R.id.balenceNo)).setText(String.valueOf(Integer.valueOf(vo.getRequiredTotalNumber()) - Integer.valueOf(vo.getAttandanceNumber())));
		((ProgressBar) convertView.findViewById(R.id.yunProgress)).setProgress(new BigDecimal(vo.getAttandanceNumber()).divide(new BigDecimal(vo.getRequiredTotalNumber()), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")).intValue());
		App.bitmapUtils.display((ImageView) convertView.findViewById(R.id.yungouImg), vo.getThumbnailUrl());

		return convertView;
	}
	
	private Double getMagnitude(String magnitudeStr) {
		Double magnitude = Double.valueOf("0");
		try {
			magnitude = Double.valueOf(magnitudeStr);
		} catch (Exception e) {
		}
		return magnitude;
	}
	
}
